package com.dcsgo.myTankGameServers.test;

import java.io.*;
import java.net.Socket;

/**
 * @author DCSGO
 * @version 1.0
 */
public class sendSomething extends Thread {
    public static boolean loop = true;
    private final Socket socket;

    public sendSomething(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream ips = socket.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(ips);
            OutputStream ops = socket.getOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(ops);
            while (loop) {
                try {
                    Object o = ois.readObject();
                    if ("下了".equals(o)) {
                        loop = false;
                        ois.close();
                        oos.close();
                        break;
                    }
                    oos.writeObject("收到！");
                    System.out.println(o);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
